package com.api.user.controller;
import com.api.core.controller.Ctrl;
import com.api.core.response.Result;
import com.api.core.response.ResultGenerator;
import com.api.user.model.Fqa;
import com.api.user.model.FqaCategory;
import com.api.user.service.FqaCategoryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import tk.mybatis.mapper.entity.Condition;
import tk.mybatis.mapper.entity.Example;
import javax.annotation.Resource;
import java.util.List;
import com.api.core.annotation.PowerEnable;
import io.swagger.annotations.*;



/**
* Created by wanghuiwen on 2021/07/20.
*/
@PowerEnable(name = "fqa_category",url = "/fqa/category")
@Api(value = "fqa_category", tags = {"fqa_category"})
@RestController
@RequestMapping("/fqa/category")
public class FqaCategoryController extends Ctrl{
    @Resource
    private FqaCategoryService fqaCategoryService;

    @ApiOperation(value = "fqa_category添加", tags = {"fqa_category"}, notes = "fqa_category添加")
    @PostMapping(value="/add",name="fqa_category添加")
    public Result add(String category) {
        FqaCategory fqaCategory = new FqaCategory();
        fqaCategory.setFqaCategory(category);
        fqaCategoryService.save(fqaCategory);
        return ResultGenerator.genSuccessResult();
    }

    @ApiOperation(value = "fqa_category删除", tags = {"fqa_category"}, notes = "fqa_category删除")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id",required=true, value = "fqa_categoryid", dataType = "Long", paramType = "query")
    })
    @PostMapping(value="/delete",name="fqa_category删除")
    public Result delete(@RequestParam Long id) {
        FqaCategory category = fqaCategoryService.findById(id);
        category.setDel(true);
        fqaCategoryService.update(category);

        return ResultGenerator.genSuccessResult();
    }

    @ApiOperation(value = "fqa_category修改", tags = {"fqa_category"}, notes = "fqa_category修改,对象主键必填")
    @PostMapping(value="/update",name="fqa_category修改")
    public Result update(@ApiParam FqaCategory fqaCategory) {
        fqaCategoryService.update(fqaCategory);
        return ResultGenerator.genSuccessResult();
    }

    @ApiOperation(value = "fqa_category列表信息", tags = {"fqa_category"}, notes = "fqa_category列表信息")
    @PostMapping(value = "/list", name = "fqa_category列表信息")
    public Result list() {
        Condition condition = new Condition(FqaCategory.class);
        condition.createCriteria().andEqualTo("del",false);
        List<FqaCategory> categories =  fqaCategoryService.findByCondition(condition);
        return ResultGenerator.genSuccessResult(categories);
    }
}
